package cn.zc.curriculum.service.service.impl;


import cn.tools.core.VO.PageVO;
import cn.tools.core.exception.BizException;
import cn.tools.core.utils.mybatis.PageUtil;
import cn.tools.dozer.config.DozerUtils;

import cn.zc.curriculum.entity.CurriculumClassify;
import cn.zc.curriculum.entity.Dto.CurriculumClassifyDto;
import cn.zc.curriculum.entity.VO.CurriculumClassifyVO;
import cn.zc.curriculum.service.mapper.CurriculumClassifyMapper;
import cn.zc.curriculum.service.service.CurriculumClassifyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 课程大类 服务实现类
 * </p>
 *
 * @author keno
 * @since 2022-02-14
 */
@Service
public class CurriculumClassifyServiceImpl extends ServiceImpl<CurriculumClassifyMapper, CurriculumClassify> implements CurriculumClassifyService {

    @Resource
    private CurriculumClassifyMapper curriculumClassifyMapper;

    @Resource
    private DozerUtils dozerUtils;


    @Override
    public void createCurriculumClassify(CurriculumClassifyDto curriculumClassifyDto) {
        CurriculumClassify classify = dozerUtils.map(curriculumClassifyDto, CurriculumClassify.class);
        boolean save = save(classify);
        if(!save){
            throw new BizException("创建课程失败");
        }
    }

    @Override
    public CurriculumClassifyDto[] findCurriculumClassify(PageVO pageVO, CurriculumClassifyVO curriculumClassifyVO) {

        CurriculumClassifyDto[] curriculumClassify = curriculumClassifyMapper.findCurriculumClassify(PageUtil.initPage(pageVO), curriculumClassifyVO);
        return curriculumClassify;
    }


    @Override
    public void updateCurriculumClassify(CurriculumClassifyDto curriculumClassifyDto) {
        CurriculumClassify classify = dozerUtils.map(curriculumClassifyDto, CurriculumClassify.class);
        boolean update = updateById(classify);
        if(!update){
            throw new BizException("修改课程失败");
        }
    }

    @Override
    public void deleteCurriculumClassify(String id) {
        boolean remove = removeById(id);
        if(!remove){
            throw new BizException("删除失败");
        }
    }
}
